package com.sjd.web.controller.mall;

import com.sjd.common.core.controller.BaseController;
import com.sjd.common.core.domain.AjaxResult;
import com.sjd.common.core.page.TableDataInfo;
import com.sjd.common.utils.poi.ExcelUtil;
import com.sjd.farm.domain.dto.order.WebFarmOrderQryRequestDTO;
import com.sjd.farm.domain.dto.order.WebFarmOrderQryResponseDTO;
import com.sjd.farm.service.WebFarmOrderService;
import com.sjd.mall.domain.dto.base.OrderNoRequestDTO;
import com.sjd.mall.domain.dto.order.WebCourierEntryRequestDTO;
import com.sjd.mall.domain.dto.order.WebOrderQryRequestDTO;
import com.sjd.mall.domain.dto.order.WebOrderQryResponseDTO;
import com.sjd.mall.service.order.WebOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * WebFarmOrder
 *
 * @author seer
 * @date 2022/2/5 13:30
 */
@Api(tags = "订单模块(管理平台)")
@RestController
@RequestMapping(value = "/order")
@Slf4j
public class WebOrderController extends BaseController {

    @Autowired
    @Qualifier("webOrderService")
    private WebOrderService service;

    /**
     * 快递录入
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "快递录入")
    @PreAuthorize("@ss.hasPermi('order:courierEntry')")
    @PostMapping(value = "/courierEntry")
    public AjaxResult courierEntry(@Validated @RequestBody WebCourierEntryRequestDTO requestDTO) {
        log.info("快递录入,请求 {}", requestDTO);
        AjaxResult result = service.courierEntry(requestDTO);
        log.info("快递录入,响应 {}", result);
        return result;
    }

    /**
     * 订单查询
     *
     * @param requestDTO requestDTO
     * @return object
     */
    @ApiOperation(value = "订单查询")
    @PreAuthorize("@ss.hasPermi('order:qry')")
    @GetMapping("/qry")
    public TableDataInfo qry(WebOrderQryRequestDTO requestDTO) {
        startPage();
        if (log.isDebugEnabled()) {
            log.debug("订单查询,请求 {}", requestDTO);
        }
        List<WebOrderQryResponseDTO> respList = service.qry(requestDTO);
        if (log.isDebugEnabled()) {
            log.debug("订单查询,响应 {}", respList);
        }
        return getDataTable(respList);
    }

    /**
     * 订单导出
     *
     * @param requestDTO requestDTO
     */
    @ApiOperation(value = "订单导出")
    @PreAuthorize("@ss.hasPermi('order:export')")
    @PostMapping("/export")
    public void export(WebOrderQryRequestDTO requestDTO, HttpServletResponse response) {
        if (log.isDebugEnabled()) {
            log.debug("订单导出,请求 {}", requestDTO);
        }
        List<WebOrderQryResponseDTO> respList = service.qry(requestDTO);
        ExcelUtil<WebOrderQryResponseDTO> util = new ExcelUtil<>(WebOrderQryResponseDTO.class);
        util.exportExcel(response, respList, "订单信息");
    }
}
